package com.bd.module.returngood.ui;

import java.awt.Color;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;

import com.bd.framework.utils.UtilsTool;
import com.bd.framework.utils.SystTimeUpdateTimer;
import com.bd.framework.utils.dbutil.DBUtil;

public class ReturnedGoodPanel extends JPanel{
	private JTextField textField_3;
	private JTextField textField_4;
	private JTextField textField_5;
	private JTextField textField_6;
	private JTextField textField_7;
	private JTextField textField_8;
	private JTextField textField_11;
	private JTextField textField_12;
	private JTextField textField_13;
	private JTextField textField_14;
	private JTextField textField_15;
	private JTextField textField_16;
	private JTextField textField_17;
	private JTextField textField_18;
	private JTextField textField_19;
	private JTable table;
	private JScrollPane returnScrollPane;
	/**pcTimeTxtF,销售界面的当前本机时间*/
	private JLabel pcTimelb;
	/**获得当前屏幕分辨率宽度*/
	private 	double width = Toolkit.getDefaultToolkit().getScreenSize().getWidth();
	/**获得当前屏幕分辨率高度*/
	private double height = Toolkit.getDefaultToolkit().getScreenSize().getHeight();

	private JPanel collectPanel;
public ReturnedGoodPanel(){
	this.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u9000\u8d27", TitledBorder.CENTER, TitledBorder.TOP, null, new Color(0, 0, 0)));
	
	this.setLayout(null);
	
	//JTable的数据(销售界面)
	final DefaultTableModel goodData=new DefaultTableModel();
	table = new JTable(goodData);
	goodData.addColumn("行");
	goodData.addColumn("商品代码");
	goodData.addColumn("商品名称");
	goodData.addColumn("单价");goodData.addColumn("数量");goodData.addColumn("折率");
	goodData.addColumn("实收金额");
	//Object[] obj = {"1","00001","笔记本","6699.00","1","1.0","6699"};
	//goodData.addRow(obj);
	
	returnScrollPane = new JScrollPane(table);
	returnScrollPane.setAutoscrolls(true);
	/**
	 * 暂定整个销售界面的高度比例3:1,及销售商品信息的ScrollPane占高度的3份
	 * 宽度比位4:1,及销售商品信息的ScrollPane占高度的4份
	 * */
	returnScrollPane.setBounds(10, 20, 971, 577);
	this.add(returnScrollPane);
	
	collectPanel = new JPanel();
	collectPanel.setToolTipText("收款信息");
	collectPanel.setBorder(new TitledBorder(null, "\u6536\u6B3E\u4FE1\u606F", TitledBorder.LEADING, TitledBorder.TOP, null, null));
	collectPanel.setBounds(1061, 48, 199, 125);
	this.add(collectPanel);
	collectPanel.setLayout(null);
	
	JLabel label = new JLabel("金 额：");
	label.setFont(new Font("楷体", Font.PLAIN, 20));
	label.setBounds(10, 27, 70, 21);
	collectPanel.add(label);
	
	textField_11 = new JTextField();
	textField_11.setEditable(false);
	textField_11.setBounds(90, 30, 82, 21);
	collectPanel.add(textField_11);
	textField_11.setColumns(10);
	
	JLabel label_18 = new JLabel("实 收：");
	label_18.setFont(new Font("楷体", Font.PLAIN, 20));
	label_18.setBounds(10, 58, 70, 21);
	collectPanel.add(label_18);
	
	textField_12 = new JTextField();
	textField_12.setEditable(false);
	textField_12.setBounds(90, 61, 82, 21);
	collectPanel.add(textField_12);
	textField_12.setColumns(10);
	
	JLabel label_19 = new JLabel("应 找：");
	label_19.setFont(new Font("楷体", Font.PLAIN, 20));
	label_19.setBounds(10, 89, 70, 21);
	collectPanel.add(label_19);
	
	textField_13 = new JTextField();
	textField_13.setEditable(false);
	textField_13.setBounds(90, 92, 82, 21);
	collectPanel.add(textField_13);
	textField_13.setColumns(10);
	
	JPanel curentPanel = new JPanel();
	curentPanel.setBorder(new TitledBorder(null, "\u5F53\u524D\u4FE1\u606F", TitledBorder.LEADING, TitledBorder.TOP, null, null));
	curentPanel.setBounds(1061, 196, 199, 115);
	this.add(curentPanel);
	
	JLabel lblNewLabel = new JLabel("当前笔数");
	curentPanel.add(lblNewLabel);
	curentPanel.setLayout(null);
	
	JLabel lblNewLabel_1 = new JLabel("当前笔数：");
	lblNewLabel_1.setFont(new Font("楷体", Font.PLAIN, 20));
	lblNewLabel_1.setBounds(10, 26, 118, 18);
	curentPanel.add(lblNewLabel_1);
	
	JLabel label_20 = new JLabel("总笔数：");
	label_20.setFont(new Font("楷体", Font.PLAIN, 20));
	label_20.setBounds(10, 54, 94, 30);
	curentPanel.add(label_20);
	
	textField_14 = new JTextField();
	textField_14.setEditable(false);
	textField_14.setBounds(87, 26, 17, 0);
	curentPanel.add(textField_14);
	textField_14.setColumns(10);
	
	textField_15 = new JTextField();
	textField_15.setEditable(false);
	textField_15.setBounds(97, 27, 79, 21);
	curentPanel.add(textField_15);
	textField_15.setColumns(10);
	
	textField_16 = new JTextField();
	textField_16.setEditable(false);
	textField_16.setBounds(99, 61, 77, 21);
	curentPanel.add(textField_16);
	textField_16.setColumns(10);
	
	JPanel discountPanle = new JPanel();
	discountPanle.setToolTipText("挂单信息");
	discountPanle.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "\u6302\u5355\u4FE1\u606F", TitledBorder.LEADING, TitledBorder.TOP, null, null));
	discountPanle.setBounds(1061, 339, 199, 83);
	discountPanle.setLayout(null);
	this.add(discountPanle);
	
	JLabel lblNewLabel_2 = new JLabel("金 额：");
	lblNewLabel_2.setFont(new Font("楷体", Font.PLAIN, 20));
	lblNewLabel_2.setBounds(10, 37, 92, 18);
	discountPanle.add(lblNewLabel_2);
	
	textField_17 = new JTextField();
	textField_17.setEditable(false);
	textField_17.setBounds(99, 38, 78, 21);
	discountPanle.add(textField_17);
	textField_17.setColumns(10);
	
	JPanel memberPanel = new JPanel();
	memberPanel.setBorder(new TitledBorder(null, "\u4F1A\u5458\u4FE1\u606F", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
	memberPanel.setBounds(1061, 460, 199, 125);
	memberPanel.setLayout(null);
	this.add(memberPanel);
	
	JLabel label_21 = new JLabel("卡 号：");
	label_21.setFont(new Font("楷体", Font.PLAIN, 20));
	label_21.setBounds(10, 32, 75, 21);
	memberPanel.add(label_21);
	
	JLabel label_22 = new JLabel("会员星级：");
	label_22.setFont(new Font("楷体", Font.PLAIN, 20));
	label_22.setBounds(10, 77, 114, 18);
	memberPanel.add(label_22);
	
	textField_18 = new JTextField();
	textField_18.setEditable(false);
	textField_18.setBounds(105, 20, 75, 21);
	memberPanel.add(textField_18);
	textField_18.setColumns(10);
	
	textField_19 = new JTextField();
	textField_19.setEditable(false);
	textField_19.setBounds(105, 77, 75, 21);
	memberPanel.add(textField_19);
	textField_19.setColumns(10);
	
	pcTimelb = new JLabel();
	pcTimelb.setFont(new Font("楷体", Font.PLAIN, 16));
	
	pcTimelb.setBounds(1051, 10, 244, 21);
	this.add(pcTimelb);
	
	pcTimelb.setText(UtilsTool.getDate("yyyy-MM-dd HH:mm:ss"));
	new	SystTimeUpdateTimer(pcTimelb);
	
	JLabel label_4 = new JLabel("代码:");
	label_4.setFont(new Font("楷体", Font.PLAIN, 20));
	label_4.setBounds(10, 607, 78, 31);
	this.add(label_4);
	
	textField_3 = new JTextField();
	textField_3.setBounds(75, 614, 66, 21);
	this.add(textField_3);
	textField_3.setColumns(10);
	
	JLabel label_5 = new JLabel("数量:");
	label_5.setFont(new Font("楷体", Font.PLAIN, 20));
	label_5.setBounds(167, 607, 54, 31);
	this.add(label_5);
	
	textField_4 = new JTextField();
	textField_4.setBounds(224, 614, 78, 21);
	this.add(textField_4);
	textField_4.setColumns(10);
	
	JLabel label_6 = new JLabel("折率:");
	label_6.setFont(new Font("楷体", Font.PLAIN, 20));
	label_6.setBounds(329, 617, 54, 21);
	this.add(label_6);
	
	textField_5 = new JTextField();
	textField_5.setBounds(406, 614, 87, 21);
	this.add(textField_5);
	textField_5.setColumns(10);
	
	JLabel label_7 = new JLabel("实收金额:");
	label_7.setFont(new Font("楷体", Font.PLAIN, 20));
	label_7.setBounds(503, 607, 124, 31);
	this.add(label_7);
	
	textField_6 = new JTextField();
	textField_6.setBounds(616, 614, 98, 21);
	this.add(textField_6);
	textField_6.setColumns(10);

	JLabel label_8 = new JLabel("收银员:");
	label_8.setFont(new Font("楷体", Font.PLAIN, 20));
	label_8.setBounds(329, 648, 87, 28);
	this.add(label_8);
	
	textField_7 = new JTextField();
	textField_7.setBounds(406, 658, 87, 21);
	this.add(textField_7);
	textField_7.setColumns(10);
	
	JLabel label_9 = new JLabel("磁卡号:");
	label_9.setFont(new Font("楷体", Font.PLAIN, 20));
	label_9.setBounds(503, 648, 103, 28);
	this.add(label_9);
	
	textField_8 = new JTextField();
	textField_8.setBounds(616, 654, 98, 21);
	this.add(textField_8);
	textField_8.setColumns(10);

	JButton btnNewButton = new JButton("确定");
	btnNewButton.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			String goodcode=textField_3.getText();
			DBUtil dt=new DBUtil();
			String[] values={goodcode};
			String goodname;
			String goodprice;
			String ssje=textField_6.getText();
			textField_12.setText(ssje);
	    	String sql="select g.GOODSCODE ,g.GOODSNAME , gp.RETAILPRICE from INFO_GOODS g,INFO_GOODSPRICE  gp where gp.GOODSCODE=g.GOODSCODE and gp.GOODSCODE=:goodsCode and gp.MARKETCODE='0101' ";
	    	try {
	    		ResultSet rs=dt.executeQuery(sql, values);
				while(rs.next()){
					goodname=rs.getString(2);
					goodprice=rs.getString(3);
					Object[] obj = {1,goodcode,goodname,goodprice,"1","1.0",goodprice};
					goodData.addRow(obj);
				}
				
				
			} catch (Exception e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
	    	textField_3.setText("");
		}
	});
	btnNewButton.setBounds(128, 717, 93, 23);
	this.add(btnNewButton);
}
}
